package com.fh.controller;/**
 * 描述:
 * Author:袁亚强
 * Date:2021/11/2415:33
 */

import com.fh.common.yyqData;
import com.fh.entity.po.Brand;
import com.fh.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * created by macro on 2021/11/24,
 */
@RestController
@RequestMapping("brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    @GetMapping("queryAllBrandData")
    public yyqData queryAllBrandData(){
        return yyqData.success(brandService.queryAllBrandData());
    }
    @GetMapping("queryById")
    public yyqData queryById(Integer id){
        if (id==null){
            return yyqData.error(400, "缺少参数");
        }
        return yyqData.success(brandService.queryById(id));
    }


    @PostMapping("updateBrand")
    public yyqData updateBrand(Brand brand){
        if (brand.getId()==null){
            return yyqData.error(400, "缺少参数");
        }
        brandService.updateBrand(brand);
        return yyqData.success("");
    }

    @PostMapping("addBrand")
    public yyqData addBrand(Brand brand){
        brandService.addBrand(brand);
        return yyqData.success("");
    }


    @PostMapping("queryByName")
    public yyqData queryByName(String name){
        if (StringUtils.isEmpty(name)){
            return yyqData.error(400, "缺少参数");
        }
        return yyqData.success(brandService.queryByName(name));
    }

}
